<template>
  <router-view />
</template>

<script setup lang="ts">
import { onMounted } from "vue";
import { useUserStore } from "./store/model/user";
import { getWxSign } from "@/services";
import wx from "weixin-js-sdk";

onMounted(() => {
  const userStore = useUserStore();
  const url = encodeURIComponent(location.href.split("#")[0]);
  getWxSign(url).then((res) => {
    if (res.data.success) {
      const appId: string = res.data.data.appId;
      const timestamp: number = res.data.data.timestamp;
      const nonceStr: string = res.data.data.noncestr;
      const signature: string = res.data.data.signature;
      wx.config({
        debug: false,
        appId,
        timestamp,
        nonceStr,
        signature,
        jsApiList: ["getLocation", "startRecord", "stopRecord",'uploadVoice','onVoiceRecordEnd'],
        openTagList: [],
      });
    }
  });
  // userStore.setUser({ id: '111-111', name: "test" });
  // userStore.setToken('i m any token')
  // todo 添加监听事件,设置用户和token
  // window.addEventListener('message',() => {
  //   // set user and token
  // })
});
</script>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  height: 100vh;
  width: 100vw;
}
body {
  margin: 0;
}
* {
  box-sizing: border-box;
}
</style>
